//
//  UIBarButtonItem+Exienion.m
//  weibo-OC
//
//  Created by diyuyma on 16/3/30.
//  Copyright © 2016年 zhangkaiyun. All rights reserved.
//

#import "UIBarButtonItem+Exienion.h"

@implementation UIBarButtonItem (Exienion)

- (void)initWithImageName: (NSString *)imageName Target: (id)target ActionName: (NSString *)actionName {
    //自定义barbuttonItem的便利构造函数
    //通过图片
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:imageName] forState:(UIControlStateNormal)];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted", imageName]] forState:(UIControlStateHighlighted)];
    NSString *Action = actionName;
    id targetObj = target;
    if ([Action  isEqual: @"selectPicture"] || targetObj != nil) {
        [btn addTarget:targetObj action:@selector(selectPicture) forControlEvents:(UIControlEventTouchUpInside)];
    }
    [btn sizeToFit];
    [self initWithCustomView:btn];
}


@end
